#!/bin/bash

COUNT=0
while read line
do
	DCOUNT=`printf "%02d\n" $COUNT`
	duration=`ffmpeg -i "$line" 2>&1 | grep Duration | sed -e 's/Duration: //g' | sed -e 's/, start.*$//g' | sed -e 's/^\s*//g' | sed -e 's/^[ \t]*//g'`
	echo "CHAPTER${DCOUNT}=${duration}.000"
	echo "CHAPTER${DCOUNT}NAME=Chapter ${DCOUNT}"
	#let COUNT=${COUNT}+1
	COUNT=$(($COUNT + 1))
done

exit 0

duration=`ffmpeg -i /Volumes/iMovie/iMovie\ Events.localized/Sofiane\ Diaporama/Sofiane_Diaporama_200910.mov 2>&1 | grep Duration | sed -e 's/Duration: //g' | sed -e 's/, start.*$//g' | sed -e 's/^\s*//g' | sed -e 's/^[ \t]*//g'`

exit 0

"mkvmerge" -o "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200905_to_201108.mkv"  "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200905.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200906.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200907.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200908.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200909.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200910.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_200911_200912.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201001.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201002.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201003.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201004_201005.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201006.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201007_201008.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201010_201011.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201012.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201101.mov" "--language" "1:eng" "--forced-track" "1:no" "--language" "2:eng" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201103.mov" "--forced-track" "1:no" "--forced-track" "2:no" "-a" "1" "-d" "2" "-S" "-T" "--no-global-tags" "--no-chapters" "/Volumes/iMovie/iMovie Events.localized/Sofiane Diaporama/Sofiane_Diaporama_201108.mov" "--track-order" "0:1,0:2,1:1,1:2,2:1,2:2,3:1,3:2,4:1,4:2,5:1,5:2,6:1,6:2,7:1,7:2,8:1,8:2,9:1,9:2,10:1,10:2,11:1,11:2,12:1,12:2,13:1,13:2,14:1,14:2,15:1,15:2,16:1,16:2,17:1,17:2"

echo "=${duration}=
